package com.aier.admin.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.common.AdminFinalPageSize;
import com.aier.admin.service.IAdminVideoService;
import com.aier.common.common.Constant;
import com.aier.common.dao.ICommonDAO;
import com.aier.entrance.common.EntranceICFinalData;
import com.aier.entrance.common.EntranceServerData;
import com.aier.entrance.entity.VideoDevice;

/**
 * 后台管理视频设备的管理 包含添加视频信息(videoReg),删除视频信息
 * (videodelete),修改视频信息(videoupdate),显示视频信息(videolist)
 * 
 * @author sun
 * 
 */
@Scope("prototype")
@Component("adminVideoDeviceAction")
public class AdminVideoDeviceAction extends AdminBaseAction {
    @Resource(name = "adminVideoService")
    private IAdminVideoService adminVideoService;
    private Map<Short, String> vs = EntranceServerData.videoSupplier;

    // 设备sn
    private String sn;
    // id
    private Long vid;
    // 状态
    private Short state;
    // 用户名
    private String user;
    // 密码
    private String pwd;
    // url
    private String url;
    // 设备厂家
    private Short supplier;
    private VideoDevice videoDevice;
    private int s;

    // 当前页
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    /**
     * 
     * @return s 0:失败 2:数据非法 1:成功
     */
    private List<VideoDevice> vilist;

    private static final long serialVersionUID = 1L;

    /**
     * 添加视频信息
     */
    public String videoReg() {

        VideoDevice vd = new VideoDevice();
        vd.setSn(sn);
        if (null == state) {
            s = 0;
            return SUCCESS;
        }
        if (state == 0) {
            vd.setState(EntranceICFinalData.VIDEO_STATE_OFF);
        } else if (state == Constant.num_10) {
            vd.setState(EntranceICFinalData.VIDEO_STATE_ON);
        } else {
            s = 2;
            return SUCCESS;
        }
        vd.setUser(user);
        vd.setPwd(pwd);
        vd.setUrl(url);
        vd.setSupplier(supplier);
        s = adminVideoService.insertEntrance(vd);
        return SUCCESS;
    }

    /**
     * 显示视频信息
     */
    @SuppressWarnings("unchecked")
    public String videolist() {
        if (page <= 0) {
            page = 1;
        }
        Map<String, Object> map = null;
        map = adminVideoService.searchVideoDevice(page, AdminFinalPageSize.VIDEO_DEVICE_PAGESIZE);
        vilist = (List<VideoDevice>) map.get(ICommonDAO.OBJ_LIST);
        if (null == vilist) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }

    /**
     * 删除视频信息
     */
    public String videodelete() {
        s = adminVideoService.updateVideoByid(vid);
        return SUCCESS;
    }

    /**
     * 修改视频信息
     */
    public String videoupdate() {
        if (null == state) {
            s = 0;
            return SUCCESS;
        }
        if (state == 0) {
            state = EntranceICFinalData.VIDEO_STATE_OFF;
        } else if (state == Constant.num_10) {
            state = EntranceICFinalData.VIDEO_STATE_ON;
        } else {
            s = 2;
            return SUCCESS;
        }

        s = adminVideoService.updateByvid(vid, sn, state, user, pwd, url,
                supplier);

        return SUCCESS;
    }

    /**
     * 根据vid查询某条视频记录
     * 
     * @return
     */
    public String searchentrbyvid() {
        videoDevice = adminVideoService.searchByvid(vid);

        return SUCCESS;
    }

    public void setAdminVideoService(IAdminVideoService adminVideoService) {
        this.adminVideoService = adminVideoService;
    }

    public int getS() {
        return s;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public void setState(Short state) {
        this.state = state;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<VideoDevice> getVilist() {
        return vilist;
    }

    public String getSn() {
        return sn;
    }

    public Short getState() {
        return state;
    }

    public String getUser() {
        return user;
    }

    public String getPwd() {
        return pwd;
    }

    public String getUrl() {
        return url;
    }

    public void setS(int s) {
        this.s = s;
    }

    public Long getVid() {
        return vid;
    }

    public void setVid(Long vid) {
        this.vid = vid;
    }

    public Short getSupplier() {
        return supplier;
    }

    public void setSupplier(Short supplier) {
        this.supplier = supplier;
    }

    public VideoDevice getVideoDevice() {
        return videoDevice;
    }

    public void setVideoDevice(VideoDevice videoDevice) {
        this.videoDevice = videoDevice;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public int getCount() {
        return count;
    }

    public Map<Short, String> getVs() {
        return vs;
    }

}
